<?php


namespace App\Model\Dao;


use App\Concern\BaseDao;
use Hyperf\Database\Query\Builder;
use Hyperf\DbConnection\Db;
use Hyperf\Utils\Arr;

/**
 * Class BankInfoLogDao
 *
 * @package App\Model\Dao
 */
class BankInfoLogDao extends BaseDao {

    const TABLE = 'bank_info_log';

    protected $softDelete = null;

    public static function table (): string {
        return self::TABLE;
    }

    public function _buildOrder (Builder $builder, $params = []) {

        $builder->orderBy('main.createTime', 'desc');
        $builder->orderBy('main.id', 'desc');

        return $builder;
    }

    public function _buildQueryString ($params) {

        $main = sprintf('%s AS main', self::TABLE);

        $builder = Db::table($main);

        Arr::exists($params, 'bankName') && $builder->where('main.bankName', 'like', "%{$params['bankName']}%");
        Arr::exists($params, 'bankNo') && $builder->where('main.bankNo', 'like', "%{$params['bankNo']}%");
        Arr::exists($params, 'bankId') && $builder->where('main.bankId', $params['bankId']);

        return $builder;
    }
}
